#!/bin/bash
# The logic to start up your application should be put in this
# script. The application will work only if it binds to
# $OPENSHIFT_DIY_IP:8080
set -x
echo "Start beego ........."


#### check the go runtime
if [ ! -d $OPENSHIFT_DATA_DIR/go ]; then
   {
       cd $OPENSHIFT_DATA_DIR
       echo "Go runtime don't exist, Start download"
       curl -NOL http://go.googlecode.com/files/go1.1.2.linux-amd64.tar.gz
       tar -xvf go1.1.2.linux-amd64.tar.gz
   }   
fi

 
export GOROOT=$OPENSHIFT_DATA_DIR/go
export GOBIN=$GOROOT/bin
export GOPATH=$OPENSHIFT_DATA_DIR/goPath
export PATH=$PATH:$GOBIN:$GOPATH/bin

mkdir -p $GOPATH
rm -rf $GOPATH/* 2>/dev/null
cp -rf $OPENSHIFT_REPO_DIR/goPath/* $GOPATH
echo "start build bee.........."
mkdir -p $GOPATH/bin
cd $GOPATH/bin
go build github.com/astaxie/bee
cd $GOPATH/src
echo "add the http ip to the app conf"
echo "httpaddr = $OPENSHIFT_DIY_IP" >> $GOPATH/src/beego/conf/app.conf
  
 cd $GOPATH/src/beego/
 nohup bee run beego &




   